home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 026-050 / 049 / plot / plotter.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  12KB  |  523 lines

  1. /* plotter.c */
  2.  
  3. double a1,a2,b1,b2,b3,x,y,zcord;
  4. char trig,stash;
  5. char z[30],temp[30];
  6. short converted[15],h,h1,v,v1;
  7. extern SHORT mx,my;
  8. double store1,store2,store3,temp1;
  9. int length,spin,tip,again;
  10. extern double magx,magy;
  11. extern int SPCos(),SPSin(),SPTieee(),SPFieee(),SPAtan(),SPTan();
  12. plotter()
  13. {
  14.    double rd,xsp,ysp,ymax,xmax,ymin,xmin;
  15.  
  16.    ymax=3.0;
  17.    ymin=-3.0;
  18.    xmax=3.0;
  19.    xmin=-3.0;
  20.    xsp=(xmax-xmin)/14.0;
  21.    ysp=(ymax-ymin)/14.0;
  22.    xmax+=.05;
  23.    ymax+=.05;
  24.    strcpy(temp,z);
  25.    SetAPen(rp,31);
  26.    SetDrMd(w->RPort,JAM1);
  27.    RectFill(w->RPort,0,0,319,199);
  28.    SetAPen(rp,4);
  29.    rd=3.14159/180.0;
  30.    a1=cos(spin*rd);
  31.    a2=sin(spin*rd);
  32.    b1=-sin(tip*rd)*sin(spin*rd);
  33.    b2=sin(tip*rd)*cos(spin*rd);
  34.    b3=cos(tip*rd);
  35.    for (x=xmin;x<=xmax;x+=xsp){
  36.       y=ymin;
  37.       if(x==xmin)
  38.          translate();
  39.       process();
  40.       scale();
  41.       h1=h;
  42.       v1=v;
  43.       for (y=ymin;y<=ymax;y+=ysp){
  44.          process();
  45.          scale();
  46.          if (v1<0)
  47.            v1=-10;
  48.          if (v1>200)
  49.             v1=210;
  50.          if (h1<0)
  51.             h1=-10;
  52.          if (h1>319)
  53.             h1=330;
  54.          if (v<0)
  55.             v=-10;
  56.          if (v>200)
  57.             v=210;
  58.          if (h<0)
  59.             h=-10;
  60.          if (h>319)
  61.             h=330;
  62.          Move(rp,h1,v1);
  63.          Draw(rp,h,v);
  64.          h1=h;
  65.          v1=v;
  66.       }
  67.    }
  68.    for (y=ymin;y<=ymax;y+=ysp){
  69.       x=xmin;
  70.       process();
  71.       scale();
  72.       h1=h;
  73.       v1=v;
  74.       for (x=xmin;x<=xmax;x+=xsp){
  75.          process();
  76.          scale();
  77.          if (v1<0)
  78.            v1=-10;
  79.          if (v1>200)
  80.             v1=210;
  81.          if (h1<0)
  82.             h1=-10;
  83.          if (h1>319)
  84.             h1=330;
  85.          if (v<0)
  86.             v=-10;
  87.          if (v>200)
  88.             v=210;
  89.          if (h<0)
  90.             h=-10;
  91.          if (h>319)
  92.             h=330;
  93.          Move(rp,h1,v1);
  94.          Draw(rp,h,v);
  95.          h1=h;
  96.          v1=v;
  97.       }
  98.    }
  99. }
  100.  
  101. scale()
  102. {
  103.    double q,p;
  104.  
  105.    q=a1*x+a2*y;
  106.    q=q*magx+(double)mx;
  107.    h=(short)q;
  108.    p=b1*x+b2*y+b3*zcord;
  109.    p=(double)my-p*magy;
  110.    v=(short)p;
  111. }
  112.  
  113. translate()
  114. {
  115.    char reduce[30],symbol;
  116.    register int a,n;
  117.  
  118.    length=strlen(temp)-1;
  119.    for (n=0;n<=length;n++){
  120.       symbol=temp[n];
  121.       converted[n]=0;
  122.       switch(symbol) {
  123.          case 'x':
  124.          case 'X':
  125.             converted[n]=-1;
  126.             break;
  127.          case 'y':
  128.          case 'Y':
  129.             converted[n]=-2;
  130.             break;
  131.          case '*':
  132.             converted[n]=-3;
  133.             break;
  134.          case '-':
  135.             converted[n]=-4;
  136.             break;
  137.          case '/':
  138.             converted[n]=-5;
  139.             break;
  140.          case '+':
  141.             converted[n]=-6;
  142.             break;
  143.          case 's':
  144.          case 'S':
  145.             converted[n]=-7;
  146.             if(toupper(temp[n+1])=='I')
  147.                temp[n+1]='0';
  148.             if(toupper(temp[n+2])=='N')
  149.                temp[n+2]='0';
  150.             break;
  151.          case 'c':
  152.          case 'C':
  153.             converted[n]=-8;
  154.             if(toupper(temp[n+1])=='O')
  155.                temp[n+1]='0';
  156.             if(toupper(temp[n+2])=='S')
  157.                temp[n+2]='0';
  158.             break;
  159.          case 't':
  160.          case 'T':
  161.             converted[n]=-9;
  162.             if(toupper(temp[n+1])=='A')
  163.                temp[n+1]='0';
  164.             if(toupper(temp[n+2])=='N')
  165.                temp[n+2]='0';
  166.             break;
  167.          case 'a':
  168.          case 'A':
  169.             converted[n]=-10;
  170.             if(toupper(temp[n+1])=='T')
  171.                temp[n+1]='0';
  172.             if(toupper(temp[n+2])=='N')
  173.                temp[n+2]='0';
  174.             break;
  175.          case '(':
  176.          case ' ':
  177.          case ')':
  178.          case '0':
  179.             converted[n]=0;
  180.             break;
  181.          default:
  182.             converted[n]=symbol-48;
  183.       }
  184.    }
  185.    a=0;
  186.    for (n=0;n<=length;n++){
  187.       if (converted[n]!=0){
  188.          reduce[a]=converted[n];
  189.          a++;
  190.       }
  191.    }
  192.    a--;
  193.    for (n=0;n<=a;n++)
  194.       converted[n]=reduce[n];
  195.    length=a;
  196. }
  197.  
  198. process()
  199. {
  200.    register int convert,n,num;
  201.  
  202.    zcord=0;
  203.    num=0;
  204.    store1=0;
  205.    store2=0;
  206.    store3=0;
  207.    stash='0';
  208.    trig='0';
  209.    again=0;
  210.    for (n=0;n<=length;n++){
  211.       convert=converted[n];
  212.       if (convert>0){
  213.          num++;
  214.          if (num==1){
  215.             store1=convert;
  216.             if (n==length)
  217.                tally();
  218.             else
  219.                if (num>10 && converted[n+1] <-2)
  220.                   tally();
  221.          }
  222.          if (num>1 && num<11){
  223.             store1=store1*convert;
  224.             if (n==length)
  225.                tally();
  226.             else
  227.                if (num>10 && converted[n+1] <-2)
  228.                   tally();
  229.          }
  230.          if (num==11){
  231.             store2=convert;
  232.             if (n==length)
  233.                tally();
  234.             else{
  235.                if (num>10 && converted[n+1]<-2 && converted[n+1]>-7)
  236.                   tally();
  237.             }
  238.          }
  239.          if (num>11){
  240.             store2=store2*convert;
  241.             if (n==length)
  242.                tally();
  243.             else{
  244.                if (num>10 && converted[n+1]<-2 && converted[n+1]>-7)
  245.                   tally();
  246.             }
  247.          }
  248.       }
  249.       else {
  250.          switch(convert){
  251.             case -1:
  252.                num++;
  253.                if (num==1){
  254.                   store1=x;
  255.                   if (n==length){
  256.                      tally();
  257.                      break;
  258.                   }
  259.                   if (num>10 && converted[n+1] <-2)
  260.                      tally();
  261.                   break;
  262.                }
  263.                if (num>1 && num<11){
  264.                   store1=store1*x;
  265.                   if (n==length){
  266.                      tally();
  267.                      break;
  268.                   }
  269.                   if (num>10 && converted[n+1] <-2)
  270.                      tally();
  271.                   break;
  272.                }
  273.                if (num==11){
  274.                   store2=x;
  275.                   if (n==length){
  276.                      tally();
  277.                      break;
  278.                   }
  279.                   if (num>10 && converted[n+1] <-2)
  280.                      tally();
  281.                   break;
  282.                }
  283.                if (num>11){
  284.                   store2=store2*x;
  285.                   if (n==length){
  286.                      tally();
  287.                      break;
  288.                   }
  289.                   if (num>10 && converted[n+1] <-2)
  290.                      tally();
  291.                }
  292.                break;
  293.             case -2:
  294.                num++;
  295.                if (num==1){
  296.                   store1=y;
  297.                   if (n==length){
  298.                      tally();
  299.                      break;
  300.                   }
  301.                   if (num>10 && converted[n+1] <-2)
  302.                      tally();
  303.                   break;
  304.                }
  305.                if (num>1 && num<11){
  306.                   store1=store1*y;
  307.                   if (n==length){
  308.                      tally();
  309.                      break;
  310.                   }
  311.                   if (num>10 && converted[n+1] <-2)
  312.                      tally();
  313.                   break;
  314.                }
  315.                if (num==11){
  316.                   store2=y;
  317.                   if (n==length){
  318.                      tally();
  319.                      break;
  320.                   }
  321.                   if (num>10 && converted[n+1] <-2)
  322.                      tally();
  323.                   break;
  324.                }
  325.                if (num>11){
  326.                   store2=store2*y;
  327.                   if (n==length){
  328.                      tally();
  329.                      break;
  330.                   }
  331.                   if (num>10 && converted[n+1] <-2)
  332.                      tally();
  333.                }
  334.                break;
  335.             case -3:
  336.                stash='*';
  337.                num=10;
  338.                again++;
  339.                break;
  340.             case -4:
  341.                stash='-';
  342.                num=10;
  343.                again++;
  344.                break;
  345.             case -5:
  346.                stash='/';
  347.                num=10;
  348.                again++;
  349.                break;
  350.             case -6:
  351.                stash='+';
  352.                num=10;
  353.                again++;
  354.                break;
  355.             case -7:
  356.                trig='S';
  357.                num=10;
  358.                again++;
  359.                store3=store1;
  360.                if (again==1){
  361.                   temp1=store1;
  362.                      if (temp1==0)
  363.                         temp1=1.0;
  364.                break;
  365.                }
  366.                else{
  367.                   temp1=store2;
  368.                      if (temp1==0)
  369.                         temp1=1.0;
  370.                }
  371.                break;
  372.             case -8:
  373.                trig='C';
  374.                num=10;
  375.                again++;
  376.                store3=store1;
  377.                if (again==1){
  378.                   temp1=store1;
  379.                      if (temp1==0)
  380.                         temp1=1.0;
  381.                break;
  382.                }
  383.                else{
  384.                   temp1=store2;
  385.                      if (temp1==0)
  386.                         temp1=1.0;
  387.                }
  388.                break;
  389.             case -9:
  390.                trig='T';
  391.                num=10;
  392.                again++;
  393.                store3=store1;
  394.                if (again==1){
  395.                   temp1=store1;
  396.                      if (temp1==0)
  397.                         temp1=1.0;
  398.                break;
  399.                }
  400.                else{
  401.                   temp1=store2;
  402.                      if (temp1==0)
  403.                         temp1=1.0;
  404.                }
  405.                break;
  406.             case -10:
  407.                trig='A';
  408.                num=10;
  409.                again++;
  410.                store3=store1;
  411.                if (again==1){
  412.                   temp1=store1;
  413.                      if (temp1==0)
  414.                         temp1=1.0;
  415.                break;
  416.                }
  417.                else{
  418.                   temp1=store2;
  419.                      if (temp1==0)
  420.                         temp1=1.0;
  421.                }
  422.                break;
  423.          }
  424.       }
  425.    }
  426. }
  427.  
  428. tally()
  429. {
  430.    if (trig!='0'){
  431.       switch(trig){
  432.          case 'S':
  433.             k1.num1=store2;
  434.             k1.i1=SPFieee(k1.i1);
  435.             k2.i2=SPSin(k1.i1); /* sin(store2) */
  436.             k2.i2=SPTieee(k2.i2);
  437.             store1=temp1*k2.num2;
  438.             zcord=store1;
  439.             store2=0;
  440.             trig='0';
  441.             break;
  442.          case 'C':
  443.             k1.num1=store2;
  444.             k1.i1=SPFieee(k1.i1);
  445.             k2.i2=SPCos(k1.i1); /* cos(store2) */
  446.             k2.i2=SPTieee(k2.i2);
  447.             store1=temp1*k2.num2;
  448.             zcord=store1;
  449.             store2=0;
  450.             trig='0';
  451.             break;
  452.          case 'T':
  453.             k1.num1=store2;
  454.             k1.i1=SPFieee(k1.i1);
  455.             k2.i2=SPTan(k1.i1); /* tan(store2) */
  456.             k2.i2=SPTieee(k2.i2);
  457.             store1=temp1*k2.num2;
  458.             zcord=store1;
  459.             store2=0;
  460.             trig='0';
  461.             break;
  462.          case 'A':
  463.             k1.num1=store2;
  464.             k1.i1=SPFieee(k1.i1);
  465.             k2.i2=SPAtan(k1.i1); /* atan(store2) */
  466.             k2.i2=SPTieee(k2.i2);
  467.             store1=temp1*k2.num2;
  468.             zcord=store1;
  469.             store2=0;
  470.             trig='0';
  471.             break;
  472.       }
  473.       switch (stash){
  474.          case '*':
  475.             store1=store3*store1;
  476.             zcord=store1;
  477.             break;
  478.          case '-':
  479.             store1=store3-store1;
  480.             zcord=store1;
  481.             break;
  482.          case '/':
  483.             store1=store3/store1;
  484.             zcord=store1;
  485.             break;
  486.          case '+':
  487.             store1=store3+store1;
  488.             zcord=store1;
  489.             break;
  490.       }
  491.    }
  492.    else{
  493.       switch(stash){
  494.          case '*':
  495.             store1=store1*store2;
  496.             zcord=store1;
  497.             again++;
  498.             store2=0;
  499.             break;
  500.          case '-':
  501.             store1=store1-store2;
  502.             zcord=store1;
  503.             again++;
  504.             store2=0;
  505.             break;
  506.          case '/':
  507.             store1=store1/store2;
  508.             zcord=store1;
  509.             again++;
  510.             store2=0;
  511.             break;
  512.          case '+':
  513.             store1=store1+store2;
  514.             zcord=store1;
  515.             again++;
  516.             store2=0;
  517.             break;
  518.          default:
  519.             zcord=store1;
  520.       }
  521.    }
  522. }
  523.